package com.easemob.chat;

import com.easemob.util.EMLog;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import org.jivesoftware.smack.Roster;
import org.jivesoftware.smack.RosterEntry;
import org.jivesoftware.smack.RosterListener;
import org.jivesoftware.smack.packet.Presence;
import org.jivesoftware.smack.packet.RosterPacket.ItemStatus;
import org.jivesoftware.smack.packet.RosterPacket.ItemType;

class EMRosterListener
  implements RosterListener
{
  private static final String TAG = "contact";
  private EMContactManager contactManager;
  private Roster roster;

  public EMRosterListener(EMContactManager paramEMContactManager, Roster paramRoster)
  {
    this.contactManager = paramEMContactManager;
    this.roster = paramRoster;
  }

  public void entriesAdded(Collection<String> paramCollection)
  {
    EMLog.d("contact", "on contact entries added:" + paramCollection);
    ArrayList localArrayList = new ArrayList();
    Iterator localIterator = paramCollection.iterator();
    while (localIterator.hasNext())
    {
      String str1 = (String)localIterator.next();
      RosterEntry localRosterEntry = this.roster.getEntry(str1);
      if ((localRosterEntry.getType() != RosterPacket.ItemType.both) && (localRosterEntry.getType() != RosterPacket.ItemType.from))
      {
        EMLog.d("contact", "ignore entry type:" + localRosterEntry.getType());
      }
      else
      {
        EMLog.d("contact", "entry add: roster entry name:" + localRosterEntry.getName() + " user:" + localRosterEntry.getUser());
        String str2 = EMContactManager.getUserNameFromEid(str1);
        String str3 = EMContactManager.getBareEidFromUserName(str2);
        localArrayList.add(str2);
      }
    }
    if ((this.contactManager.contactListener != null) && (localArrayList.size() != 0))
      this.contactManager.contactListener.onContactAdded(localArrayList);
  }

  public void entriesDeleted(Collection<String> paramCollection)
  {
    EMLog.d("contact", "on contact entries deleted:" + paramCollection);
    ArrayList localArrayList = new ArrayList();
    Iterator localIterator = paramCollection.iterator();
    while (localIterator.hasNext())
    {
      String str1 = (String)localIterator.next();
      RosterEntry localRosterEntry = this.roster.getEntry(str1);
      String str2 = EMContactManager.getUserNameFromEid(str1);
      localArrayList.add(str2);
      this.contactManager.removeContactByUsername(str2);
    }
    if ((this.contactManager.contactListener != null) && (localArrayList.size() != 0))
      this.contactManager.contactListener.onContactDeleted(localArrayList);
  }

  public void entriesUpdated(Collection<String> paramCollection)
  {
    EMLog.d("contact", "on contact entries updated:" + paramCollection);
    ArrayList localArrayList1 = new ArrayList();
    ArrayList localArrayList2 = new ArrayList();
    Iterator localIterator1 = paramCollection.iterator();
    while (localIterator1.hasNext())
    {
      String str1 = (String)localIterator1.next();
      RosterEntry localRosterEntry = this.roster.getEntry(str1);
      if ((localRosterEntry.getType() == RosterPacket.ItemType.both) || (localRosterEntry.getType() == RosterPacket.ItemType.from))
      {
        String str2 = EMContactManager.getUserNameFromEid(str1);
        localArrayList1.add(str2);
      }
      EMLog.d("contact", "entry.getType() = " + localRosterEntry.getType() == null ? "null" : localRosterEntry.getType().toString());
      if (localRosterEntry.getType() == RosterPacket.ItemType.none)
      {
        if (EMContactManager.getInstance().deleteContactsSet.contains(str1))
        {
          localArrayList2.add(EMContactManager.getUserNameFromEid(str1));
        }
        else
        {
          if ((localRosterEntry.getStatus() != null) && (RosterPacket.ItemStatus.SUBSCRIPTION_PENDING.toString().equals(localRosterEntry.getStatus().toString())))
            return;
          if (this.contactManager.contactListener != null)
            this.contactManager.contactListener.onContactRefused(EMContactManager.getUserNameFromEid(str1));
        }
        try
        {
          this.roster.removeEntry(localRosterEntry);
        }
        catch (Exception localException)
        {
        }
      }
      if ((this.contactManager.contactListener != null) && (localArrayList1.size() != 0))
        this.contactManager.contactListener.onContactAdded(localArrayList1);
      if ((this.contactManager.contactListener != null) && (localArrayList2.size() != 0))
      {
        Iterator localIterator2 = localArrayList2.iterator();
        while (localIterator2.hasNext())
        {
          String str3 = (String)localIterator2.next();
          EMChatManager.getInstance().deleteConversation(str3);
        }
        this.contactManager.contactListener.onContactDeleted(localArrayList2);
      }
    }
  }

  public void presenceChanged(Presence paramPresence)
  {
  }
}

/* Location:           D:\hygieia\userclient\common\libs\easemobchat_2.1.8.jar
 * Qualified Name:     com.easemob.chat.EMRosterListener
 * JD-Core Version:    0.6.1
 */